<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/13
  Time: 19:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <link rel="stylesheet" href="css/img.css">
    <link rel="stylesheet" href="../../css/css.css">
</head>
<body>

<h1>欢迎来到添加页面</h1>

<form>
    姓名：<input type="text" name="sname"><br><br>
    照片：
    <div class="photoUpLoad" >
    <input type="file"  class="photo" name="photo" accept="image/*"><span class="cross">+</span>
    <img src="" alt="" class="photoEcho">
    </div><br><br>
    性别：
    <input type="radio" name="sex" value="男">男
    <input type="radio" name="sex" value="女">女<br>
    爱好：
    <input type="checkbox" name="hobby" value="旅游">旅游
    <input type="checkbox" name="hobby" value="摄影">摄影
    <input type="checkbox" name="hobby" value="绘画">绘画
    <input type="checkbox" name="hobby" value="吃零食">吃零食
    <input type="checkbox" name="hobby" value="化妆">化妆
    <input type="checkbox" name="hobby" value="游戏">游戏<br>
    生日：<input type="text" name="bir"><br>
    地址：
    <select name="sheng" onchange="sheng2()">
        <option value="">请选择省</option>
    </select>
    <select name="shi" onchange="shi2()">
        <option value="">请选择市</option>
    </select>
    <select name="xian">
        <option value="">请选择县</option>
    </select><br>
    课程：
    <div name="cid">

    </div><br>

</form>
<input type="button" value="添加" onclick="add()">

</body>
</html>

<script>

    $.post(
        "listcourse.do",
        function (data) {
            for (var i = 0; i <data.length ; i++) {
                $("[name='cid']").append('<input type="checkbox" name="cids" value="'+data[i].cid+'">'+data[i].cname)
            }
        }
    )

    $.post(
        "listcity.do",
        {"pid":0},
        function (data) {
            for (var i = 0; i <data.length ; i++) {
                $("[name='sheng']").append(' <option value="'+data[i].id+'">'+data[i].name+'</option>')
            }
            $("[name='sheng']").val(${map.sheng})
            $("[name='sheng']").trigger("change")
        }
    )

    function sheng2() {
        pid=$("[name='sheng']").val()
        $("[name='shi']").empty()
        $("[name='shi']").append('<option value="">请选择市</option>')
        $("[name='xian']").empty()
        $("[name='xian']").append('<option value="">请选择县</option>')
        $.post(
            "listcity.do",
            {"pid":pid},
            function (data) {

                for (var i = 0; i <data.length ; i++) {
                    $("[name='shi']").append(' <option value="'+data[i].id+'">'+data[i].name+'</option>')
                }
                $("[name='shi']").val(${map.shi})
                $("[name='shi']").trigger("change")
            }
        )
    }
    function shi2() {
        pid=$("[name='shi']").val()
        $("[name='xian']").empty()
        $("[name='xian']").append('<option value="">请选择县</option>')
        $.post(
            "listcity.do",
            {"pid":pid},
            function (data) {
                for (var i = 0; i <data.length ; i++) {
                    $("[name='xian']").append(' <option value="'+data[i].id+'">'+data[i].name+'</option>')
                }
                $("[name='xian']").val(${map.xian})
            }
        )
    }

    function add() {
        var formData = new FormData($("form")[0]);
        $.ajax({
            url:"add.do",
            data:formData,
            type:"post",
            dataType:"json",
            success:function (data) {
                if (data>0){
                    alert("添加成功")
                    location="list.do"
                }else{
                    alert("添加失败")
                }
            },processData:false,
            contentType:false

        })
    }



</script>
